package com.yidu.boss.sys.service.impl;

import com.yidu.boss.sys.dao.FundMapper;
import com.yidu.boss.sys.domain.Fund;
import com.yidu.boss.sys.domain.FundExample;
import com.yidu.boss.sys.service.FundService;
import com.yidu.boss.util.RandomString;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.dao.DataAccessException;
import org.springframework.stereotype.Service;

import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.List;
import java.util.UUID;


/**
 * @Author 32698
 * @Date 2019/11/25 13:32
 */
@Service
public class FundServicelmpl implements FundService {
    @Autowired
    private FundMapper fundMapper;

    @Override
    public List<Fund> selectAll() {
        List<Fund> funds= fundMapper.selectByExample(null);
        return funds;
    }

    public List<Fund> selectByExample(FundExample fundExample) {
        return fundMapper.selectByExample(fundExample);
    }

    /**
     * 模糊查询
     *
     * @param fund
     * @return
     */

    public List<Fund> selectLike(String fund) {
        FundExample fundExample = new FundExample();
        //模糊查询名字
        fundExample.or().andFounNoLike(fund);
        //集合
        List<Fund> fundList = fundMapper.selectByExample(fundExample);
        return fundList;
    }
    /**
     * 模糊查询所有
     * @param condition
     * @return
     */
    @Override
    public List<Fund> selectSomeByMorel(String condition) {
        //调用业务层模糊查询所有的方法
        List<Fund> fundList = fundMapper.selectSomeByMorel(condition);
        return fundList;
    }


    /**
     * 添加
     * @param fund
     * @return
     */

    @Override
    public int insertFund(Fund fund) {
        //Id
        fund.setFundId(UUID.randomUUID().toString().substring(0,6).replace("-",""));
        //基金代码
        fund.setFounNo(RandomString.getNum());
        //管理人Id
        System.out.println("fund = " + fund);
        int i = fundMapper.insertSelective(fund);
        return i;

    }
    /**
     * 修改
     * @param fund
     * @return
     */
    @Override
    public int updatefund(Fund fund) {
        //Example类
        FundExample fundExample =new FundExample();
        //获得Id
        fundExample.or().andFundIdEqualTo(fund.getFundId());
        int i =fundMapper.updateByExampleSelective(fund,fundExample);
        return i;
    }

    /**
     * 删除
     * @param id
     * @return
     */
    @Override
    public int deleteFund(String id)  throws DataAccessException {
        //
        int i =fundMapper.deleteByPrimaryKey(id);
        return i;
    }


}
